﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.Services.Contracts.DTO.Infos;
using Demo.Services.Integration.DAO.Impl;
using Demo.CommonBase.Logging;
using Demo.CommonBase.Exceptions;
using System.Reflection;
using Demo.CommonBase.DTO.Infos;
using Demo.Services.Contracts.DTO.Filters;

namespace Demo.Services.Services.Impl.DomainObjects
{
    public class ResourceTypeDomainObject
    {
        public ResourceTypeResultInfo GetResourceTypes(PaginationInfo pagin, ResourceTypeFilter filters)
        {
            ResourceTypeResultInfo result = null;
            ResourceTypeDAO resourceTypeDao;
            try
            {
                //Logger.Info();
                resourceTypeDao = new ResourceTypeDAO();
                result = resourceTypeDao.GetResourceTypeList(pagin, filters);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }

        public void SaveResourceType(ResourceTypeInfo info)
        {

            ResourceTypeDAO resourceTypeDao;
            try
            {
                //Logger.Info();
                resourceTypeDao = new ResourceTypeDAO();
                if (info.Id != 0)
                {
                    resourceTypeDao.UpdateResourceType(info);
                }
                else
                {
                    int id = resourceTypeDao.SaveResourceType(info);
                    info.Id = id;
                }
                
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }     
        }
        public ResourceTypeInfo GetResourceTypeById(int id)
        {
            ResourceTypeInfo result = null;
            ResourceTypeDAO resourceTypeDao;
            try
            {
                //Logger.Info();
                resourceTypeDao = new ResourceTypeDAO();
                result = resourceTypeDao.GetResourceTypeById(id);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }
        public void DeleteResourceType(int id)        
        {            
            ResourceTypeDAO resourceTypeDao;            
            try            
            {           
                //Logger.Info();                
                resourceTypeDao = new ResourceTypeDAO();                
                resourceTypeDao.DeleteResourceType(id);            
            }            
            catch (Exception ex)            
            {                
                Logger.Error(ex);                
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);            
            }        
        }
        public List<ResourceTypeInfo> GetList()
        {
            ResourceTypeDAO resourceTypeDao;
            List<ResourceTypeInfo> result;
            try
            {
                //Logger.Info();
                resourceTypeDao = new ResourceTypeDAO();
                result = resourceTypeDao.GetList();
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return result;
        }
        public bool CheckName(int id, string name)
        {
            bool isValid = false;
            ResourceTypeDAO resourceTypeDao;
            try
            {
                Logger.Info();
                resourceTypeDao = new ResourceTypeDAO();
                isValid = resourceTypeDao.CheckName(id, name);
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
            return isValid;
        }
    }
}
